﻿using System;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

namespace SoftwareEngineering_Project
{
    public class Reservation
    {
        DBConnection DB;//Initiate the Database object
        public SqlDataReader myReader;
        int Reservation_ID;
        public int Room_ID;
        public string Name;
        public string Organizer;
        public DateTime date;
        public DateTime STime;
        public DateTime ETime;
        public int numberofattendees;
        public int type_ID;
        public Boolean recordVideo;
        public Boolean recordAudio;
        public Boolean presentation;
        public string Username;
        //Create a new Reservation instance
        public Reservation(int Room_ID, string Name, string Organizer, DateTime date, DateTime STime, DateTime ETime,
            int numberofattendees, int type_ID, Boolean recordVideo, Boolean recordAudio, Boolean presentation, string Username)
        {
            this.Room_ID = Room_ID;
            this.Name = Name;
            this.Organizer =  Organizer;
            this.date = date;
            this.STime = STime;
            this.ETime= ETime;
            this.numberofattendees = numberofattendees;
            this.type_ID = type_ID;
            this.Username = Username;
            this.recordAudio = recordAudio;
            this.recordVideo = recordVideo;
            this.presentation = presentation;
           
        }
        public Reservation()
        {
        }
        public Boolean AddtoDataBase()
        {
            string sqlcommand;
            sqlcommand = "INSERT INTO Reservation VALUES('" + Room_ID + "','" + Name + "','" + Organizer + "','" + date + 
                "','" + STime + "','" + ETime + "','" + numberofattendees + "','" + type_ID + "','"  +
                recordAudio + "','" + recordVideo + "','" + presentation + "','" + Username + "');";

            DBConnection DB = new DBConnection();
            ////DB.cnTransact.Open();
            if (DB.ExecuteCommandNonquery(sqlcommand))
            {
                (new Logs()).CreateLog(DB, "1", "");
                return true;
            }
            else
            {   
                return false;
            }
        
        }
        public SqlDataReader getReservation(string sqlcommand)
        {
            DB = new DBConnection();
            ////DB.cnTransact.Open();
            myReader = DB.ExecuteCommandquery(sqlcommand);
            return myReader;
           
        }

        public void CloseConnection()
        {
            DB.cnTransact.Close();
        }
        public void getItem(string sqlcommand)
        {

            DBConnection DB = new DBConnection();
            ////DB.cnTransact.Open();
            myReader = DB.ExecuteCommandquery(sqlcommand);
            while (myReader.Read())
            {
                this.Room_ID = Convert.ToInt32(myReader[1]);
                this.Name = myReader[2].ToString();
                this.Organizer = myReader[3].ToString();
                this.date = Convert.ToDateTime(myReader[4]);
                this.STime = Convert.ToDateTime(myReader[5].ToString());
                this.ETime = Convert.ToDateTime(myReader[6].ToString());
                this.numberofattendees = Convert.ToInt32(myReader[7]);
                this.type_ID = Convert.ToInt32(myReader[8]);
                this.Username = myReader[12].ToString();
                this.recordAudio = Convert.ToBoolean(myReader[9]);
                this.recordVideo = Convert.ToBoolean(myReader[10]);
                this.presentation = Convert.ToBoolean(myReader[11]);
            }
         
        }
        public void SetImportantDates(Calendar mycalendar)
        {
            DBConnection DB = new DBConnection();
            ////DB.cnTransact.Open();
            myReader = DB.ExecuteCommandquery("Select Res_Date From Reservation");
            while (myReader.Read())
            {
                mycalendar.SelectedDates.Add( Convert.ToDateTime(myReader[0]));
            }

        }
        public Boolean ExcuteNoresultsQuery(String sqlCommand)
        {
            DBConnection DB = new DBConnection();
            ////DB.cnTransact.Open();
            if (DB.ExecuteCommandNonquery(sqlCommand))
            {
                return true;
            }
            else
            {
                return false;
            }
            ////DB.cnTransact.Close();
        }

    }
}